package com.sino.operation.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sino.operation.commons.response.CenterResponseEntity;
import com.sino.operation.entity.BizDictSet;
import com.sino.operation.service.BizDictSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
@RequestMapping("dictSet")
@Api(value = "字段配置接口", tags = "字段配置接口")
public class DictSetManagerController {

    @Autowired
    private BizDictSetService bizDictSetService;

    @GetMapping("/selectDictSetList")
    @ApiOperation(value = "查询交易字段列表")
    @ResponseBody
    public List<BizDictSet> getDictSetList(@RequestParam("transCode") String transCode,@RequestParam("transType")String transType){

        return bizDictSetService.selectList(transCode,transType);
    }

    @PostMapping("/addDictSet")
    @ApiOperation(value = "新增字段配置数据")
    @ResponseBody
    public CenterResponseEntity addDictSet(BizDictSet sysDictSet){
        try {
            bizDictSetService.saveOrUpdate(sysDictSet);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return CenterResponseEntity.build();
    }

    @PostMapping("/deleteDictSet")
    @ApiOperation(value = "批量删除字段配置")
    @ResponseBody
    public CenterResponseEntity deleteDictSet(List ids){
        try {
            bizDictSetService.removeByIds(ids);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }


    @PostMapping("/updateDictSet")
    @ApiOperation(value = "修改字段配置信息")
    @ResponseBody
    public CenterResponseEntity updateDictSet(BizDictSet sysDictSet){
        try {
            bizDictSetService.saveOrUpdate(sysDictSet);
        } catch (Exception e) {
            e.printStackTrace();
            return CenterResponseEntity.buildError();
        }
        return CenterResponseEntity.build();
    }
}
